
*  ==========================================================  *
*        Subnational debt under temperature shocks:            *
*                     Evidence from China                      *
*                                                              *
*                     Xiao Tian, Yong Liu                      *
*  ==========================================================  *

* data instruction
** dependent variables
      OAPratio: LGFV's other account payable over interest bearing debt
	  OARratio: LGFV's other account receivable over interest bearing debt
** weather variables
      one: days of maximum temperature <0°C quarterly
	  two: days of maximun temperature 0-5°C quarterly
	  ...
	  nine: days of maximum temperature >35°C quarterly
	  a: days of average temperature <-25°C quarterly
	  b: days of average temperature -25°C — -20°C quarterly
	  ...
	  nn: days of average temperature >35°C quarterly
	  precip, wspeed, sunshine: prefectural quarterly average  precipitation, wind speed, and sunshine duration
** LGFV accounting items
      cash: cash and cash equivalents
	  income: operating revenue
	  shortloan: bank loan that is due within one year
	  longloan: bank loan that is due within over one year
	  bond: bond payable
** locality characteristics
      urbaniz: prefectural urbanization rate of permanent resident
	  deficit: locality (prefecture or county) level government deficit rate
	  compact: city level population (record by the Public Security Sector) over built-up area
** IVs	  
	  corn, wheat: provincial corn and winterwheat yields
** others
      EGDP: prefectural GDP
	  ELEC: prefectural electric consumption
	  permresi: prefectural permanent population (the Public Security Sector speculates)
	  regiresi: prefectural registered population
	  Mseg: prefectural market segmentation index
	  tier: administrative level of LGFV (if prefecture, "2" , if county, "1")
	  prefectOAPratio: OAP ratio of LGFVs merged within prefectures
	  govdebtratio: ratio of locality (prefecture or county) level government explicit debt (including government debt and the LGFV debt) to the gross regional product
	  transparency: prefectural fiscal transparency


import excel "D:\data2.xlsx", sheet("Sheet2") firstrow clear
xtset id quarter
tab quarter, gen(dquarter)
gen debt=shortloan+longloan+bond
gen LNdebt=log(debt)
gen LNcash=log(cash)
gen LNincome=log(income)
gen n=_n
tsset n
gen one_lag=L.one
gen one_lag2=L2.one
gen one_lag3=L3.one
gen one_lag4=L4.one
gen one_lag5=L5.one
gen one_lag6=L6.one
gen one_lag7=L7.one
gen two_lag=L.two
gen two_lag2=L2.two
gen two_lag3=L3.two
gen two_lag4=L4.two
gen two_lag5=L5.two
gen two_lag6=L6.two
gen two_lag7=L7.two
gen three_lag=L.three
gen three_lag2=L2.three
gen three_lag3=L3.three
gen three_lag4=L4.three
gen three_lag5=L5.three
gen three_lag6=L6.three
gen three_lag7=L7.three
gen four_lag=L.four
gen four_lag2=L2.four
gen four_lag3=L3.four
gen four_lag4=L4.four
gen four_lag5=L5.four
gen four_lag6=L6.four
gen four_lag7=L7.four
gen five_lag=L.five
gen five_lag2=L2.five
gen five_lag3=L3.five
gen five_lag4=L4.five
gen five_lag5=L5.five
gen five_lag6=L6.five
gen five_lag7=L7.five
gen six_lag=L.six
gen six_lag2=L2.six
gen six_lag3=L3.six
gen six_lag4=L4.six
gen six_lag5=L5.six
gen six_lag6=L6.six
gen six_lag7=L7.six
gen seven_lag=L.seven
gen seven_lag2=L2.seven
gen seven_lag3=L3.seven
gen seven_lag4=L4.seven
gen seven_lag5=L5.seven
gen seven_lag6=L6.seven
gen seven_lag7=L7.seven
gen eight_lag=L.eight
gen eight_lag2=L2.eight
gen eight_lag3=L3.eight
gen eight_lag4=L4.eight
gen eight_lag5=L5.eight
gen eight_lag6=L6.eight
gen eight_lag7=L7.eight
gen nine_lag=L.nine
gen nine_lag2=L2.nine
gen nine_lag3=L3.nine
gen nine_lag4=L4.nine
gen nine_lag5=L5.nine
gen nine_lag6=L6.nine
gen nine_lag7=L7.nine
gen one1=one+two
gen one1_lag=one_lag+two_lag
gen one1_lag2=one_lag2+two_lag2
gen one1_lag3=one_lag3+two_lag3
gen one1_lag4=one_lag4+two_lag4
gen one1_lag5=one_lag5+two_lag5
gen one1_lag6=one_lag6+two_lag6
gen one1_lag7=one_lag7+two_lag7
gen a_lag=L.a
gen b_lag=L.b
gen c_lag=L.c
gen d_lag=L.d
gen e_lag=L.e
gen f_lag=L.f
gen g_lag=L.g
gen h_lag=L.h
gen i_lag=L.i
gen j_lag=L.j
gen k_lag=L.k
gen l_lag=L.l
gen m_lag=L.m
gen nn_lag=L.nn
gen a_lag2=L2.a
gen b_lag2=L2.b
gen c_lag2=L2.c
gen d_lag2=L2.d
gen e_lag2=L2.e
gen f_lag2=L2.f
gen g_lag2=L2.g
gen h_lag2=L2.h
gen i_lag2=L2.i
gen j_lag2=L2.j
gen k_lag2=L2.k
gen l_lag2=L2.l
gen m_lag2=L2.m
gen nn_lag2=L2.nn
gen a_lag3=L3.a
gen b_lag3=L3.b
gen c_lag3=L3.c
gen d_lag3=L3.d
gen e_lag3=L3.e
gen f_lag3=L3.f
gen g_lag3=L3.g
gen h_lag3=L3.h
gen i_lag3=L3.i
gen j_lag3=L3.j
gen k_lag3=L3.k
gen l_lag3=L3.l
gen m_lag3=L3.m
gen nn_lag3=L3.nn
gen a_lag4=L4.a
gen b_lag4=L4.b
gen c_lag4=L4.c
gen d_lag4=L4.d
gen e_lag4=L4.e
gen f_lag4=L4.f
gen g_lag4=L4.g
gen h_lag4=L4.h
gen i_lag4=L4.i
gen j_lag4=L4.j
gen k_lag4=L4.k
gen l_lag4=L4.l
gen m_lag4=L4.m
gen nn_lag4=L4.nn
gen precip_lag=L.precip
gen precip_lag2=L2.precip
gen precip_lag3=L3.precip
gen precip_lag4=L4.precip
gen precip_lag5=L5.precip
gen precip_lag6=L6.precip
gen precip_lag7=L7.precip
gen precip2=precip^2
gen precip2_lag=precip_lag^2
gen precip2_lag2=L2.precip2_lag
gen precip2_lag3=L3.precip2_lag
gen precip2_lag4=L4.precip2_lag
gen precip2_lag5=L5.precip2_lag
gen precip2_lag6=L6.precip2_lag
gen precip2_lag7=L7.precip2_lag
gen wspeed_lag=L.wspeed
gen wspeed_lag2=L2.wspeed
gen wspeed_lag3=L3.wspeed
gen wspeed_lag4=L4.wspeed
gen wspeed_lag5=L5.wspeed
gen wspeed_lag6=L6.wspeed
gen wspeed_lag7=L7.wspeed
gen sunshine_lag=L.sunshine
gen sunshine_lag2=L2.sunshine
gen sunshine_lag3=L3.sunshine
gen sunshine_lag4=L4.sunshine
gen sunshine_lag5=L5.sunshine
gen sunshine_lag6=L6.sunshine
gen sunshine_lag7=L7.sunshine
xtset id quarter
winsor2 one1 one1_lag one1_lag2 one1_lag3 one1_lag4 one1_lag5 one1_lag6 one1_lag7, cut(0 97.5) replace
gen daysextrm=one1+nine
gen daysextrm_lag=one1_lag+nine_lag
gen daysextrm_lag2=one1_lag2+nine_lag2
gen daysextrm_lag3=one1_lag3+nine_lag3
gen daysextrm_lag4=one1_lag4+nine_lag4
gen daysextrm_lag5=one1_lag5+nine_lag5
gen daysextrm_lag6=one1_lag6+nine_lag6
gen daysextrm_lag7=one1_lag7+nine_lag7
gen LNOAP=log(OAP)
gen OAPratio=LNOAP-LNdebt
gen OAPratio1=2.71828^OAPratio
winsor2 OAPratio LNdebt LNcash LNincome, cut(0 99.5) replace

* 3.1 Measuring LGFVs’ default risk
** Table A1
*** data preparation
by preid quarter, sort: egen prefectOAP = total(OAP)
by preid quarter, sort: egen prefectshortloan = total(shortloan)
by preid quarter, sort: egen prefectlongloan = total(longloan)
by preid quarter, sort: egen prefectbond = total(bond)
gen prefectdebt=prefectshortloan+prefectlongloan+prefectbond
gen prefectOAPratio=prefectOAP/prefectdebt
bysort preid quarter: gen set=_n
*** column 1
reghdfe transparency prefectOAPratio, absorb(preid quarter) vce(cluster preid), if season==4 & set==1
*** column 2
reghdfe transparency govdebtratio, absorb(preid quarter) vce(cluster preid), if season==4 & set==1
*** the last data quality validation includes the govenment balance sheet data that we don't have permission to disclose.


* 5.1 Baseline results
** Table 2 
*** column 1
reghdfe OAPratio nine nine_lag nine_lag2 nine_lag3 nine_lag4 nine_lag5 nine_lag6 nine_lag7 precip precip2 wspeed sunshine precip_lag precip2_lag wspeed_lag sunshine_lag precip_lag2 precip2_lag2 wspeed_lag2 sunshine_lag2 precip_lag3 precip2_lag3 wspeed_lag3 sunshine_lag3 precip_lag4 precip2_lag4 wspeed_lag4 sunshine_lag4 precip_lag5 precip2_lag5 wspeed_lag5 sunshine_lag5 precip_lag6 precip2_lag6 wspeed_lag6 sunshine_lag6 precip_lag7 precip2_lag7 wspeed_lag7 sunshine_lag7 LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id)

*** column 2
reghdfe OAPratio one1 one1_lag one1_lag2 one1_lag3 one1_lag4 one1_lag5 one1_lag6 one1_lag7 precip precip2 wspeed sunshine precip_lag precip2_lag wspeed_lag sunshine_lag precip_lag2 precip2_lag2 wspeed_lag2 sunshine_lag2 precip_lag3 precip2_lag3 wspeed_lag3 sunshine_lag3 precip_lag4 precip2_lag4 wspeed_lag4 sunshine_lag4 precip_lag5 precip2_lag5 wspeed_lag5 sunshine_lag5 precip_lag6 precip2_lag6 wspeed_lag6 sunshine_lag6 precip_lag7 precip2_lag7 wspeed_lag7 sunshine_lag7 LNcash LNincome LNdebt  urbaniz compact deficit, absorb(id quarter) vce(cluster id)

*** column 3
reghdfe OAPratio nine nine_lag nine_lag2 nine_lag3 nine_lag4 nine_lag5 nine_lag6 nine_lag7 one1 one1_lag one1_lag2 one1_lag3 one1_lag4 one1_lag5 one1_lag6 one1_lag7 precip precip2 wspeed sunshine precip_lag precip2_lag wspeed_lag sunshine_lag precip_lag2 precip2_lag2 wspeed_lag2 sunshine_lag2 precip_lag3 precip2_lag3 wspeed_lag3 sunshine_lag3 precip_lag4 precip2_lag4 wspeed_lag4 sunshine_lag4 precip_lag5 precip2_lag5 wspeed_lag5 sunshine_lag5 precip_lag6 precip2_lag6 wspeed_lag6 sunshine_lag6 precip_lag7 precip2_lag7 wspeed_lag7 sunshine_lag7 LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id)

*** column 4
reghdfe OAPratio daysextrm daysextrm_lag daysextrm_lag2 daysextrm_lag3 daysextrm_lag4 daysextrm_lag5 daysextrm_lag6 daysextrm_lag7 precip precip2 wspeed sunshine precip_lag precip2_lag wspeed_lag sunshine_lag precip_lag2 precip2_lag2 wspeed_lag2 sunshine_lag2 precip_lag3 precip2_lag3 wspeed_lag3 sunshine_lag3 precip_lag4 precip2_lag4 wspeed_lag4 sunshine_lag4 precip_lag5 precip2_lag5 wspeed_lag5 sunshine_lag5 precip_lag6 precip2_lag6 wspeed_lag6 sunshine_lag6 precip_lag7 precip2_lag7 wspeed_lag7 sunshine_lag7 LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id)

** Table 3
*** column 1
reghdfe OAPratio nine_lag one1_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id)

*** column 2
reghdfe OAPratio daysextrm_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id)

*** column 3
reghdfe OAPratio daysextrm_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id), if season==1

*** column 4
reghdfe OAPratio daysextrm_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id), if season==2

*** column 5
reghdfe OAPratio daysextrm_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id), if season==3

*** column 6
reghdfe OAPratio daysextrm_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id), if season==4

* 5.2 IV estimations
** Table 4
*** column 1
reghdfe OAPratio nine_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id), if season==4
*** column 2
reghdfe OAPratio one1_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id), if season==2
*** column 3
reghdfe OAPratio corn precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id), if season==4
*** column 4
reghdfe OAPratio wheat precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id), if season==2
*** column 5
ivreghdfe OAPratio (nine_lag=corn) precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) first vce(cluster id),if season==4
*** column 6
ivreghdfe OAPratio (one1_lag=wheat) precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) first vce(cluster id),if season==2
*** column 7
ivreghdfe OAPratio (nine_lag=corn) LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) first vce(cluster id),if season==4
*** column 8
ivreghdfe OAPratio (one1_lag=wheat) LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) first vce(cluster id),if season==2

* 5.3.1 Alternative FE and cluster SE
** Table 5
*** data preparation
gen yr=quarter-(season-1)*25
gen preidyr=preid*yr
inlist2 proid,values(81,84,87,88,89,99) name(midtemperate)
inlist2 proid,values(72,74,79,80,91,92,93,96) name(warmtemperate)
inlist2 proid,values(90,97) name(plateau)
inlist2 proid,values(71,73,75,76,77,82,83,85,86,94,95,98,100,101,102) name(subtropics)
inlist2 proid,values(78) name(tropic)
gen temperaturezone=midtemperate+warmtemperate*2+plateau*3+subtropics*4+tropic*5
gen temperaturezonequarter=temperaturezone*quarter
gen proidyr=proid*yr
gen proidseason=proid*season
gen proidquarter=proid*quarter
*** column 1
reghdfe OAPratio nine_lag one1_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id preidyr)
*** column 2
reghdfe OAPratio nine_lag one1_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster preidyr)
*** column 3
reghdfe OAPratio nine_lag one1_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster preid)
*** column 4
reghdfe OAPratio nine_lag one1_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id temperaturezonequarter) vce(cluster id)
*** column 5
reghdfe OAPratio nine_lag one1_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id proidquarter) vce(cluster id)
*** column 6
reghdfe OAPratio nine_lag one1_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id yr season) vce(cluster id)
*** column 7
reghdfe OAPratio nine_lag one1_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id proidyr proidseason) vce(cluster id)

* 5.3.2 Potential nonlinearities of temperature impacts, and alternative dependent variable 
** data preparation
winsor2 one one_lag one_lag4 , cut(0 97.5) replace
** Fig 5a
reghdfe OAPratio one_lag two_lag three_lag four_lag five_lag tier seven_lag eight_lag nine_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id)

coefplot, baselevels omitted keep(nine_lag eight_lag seven_lag tier five_lag four_lag three_lag two_lag one_lag) vertical coeflabels(one_lag = "<0°C" two_lag = "0-5°C" three_lag = "5-10°C" four_lag = "10-15°C" five_lag = "15-20°C" tier = "20-25°C" seven_lag = "25-30°C" eight_lag = "30-35°C" nine_lag = ">35°C") yline(0,lcolor(red*0.9) lwidth(medthick)) yline(-0.003,lcolor(blue*0.2)) yline(-0.002,lcolor(blue*0.2)) yline(-0.001,lcolor(blue*0.2)) yline(0.001,lcolor(blue*0.2)) yline(0.002,lcolor(blue*0.2)) yline(0.003,lcolor(blue*0.2)) yline(0.004,lcolor(blue*0.2)) ylabel(-0.003(0.001)0.004) xline(10, lwidth(vthin) lpattern(dash) lcolor(red)) ylabel(,labsize(*0.9)) xlabel(,labsize(*0.9))  ytitle("Change in OAP ratio", size(medium)) xtitle("Daily max temperature bins in t-1", size(medium)) addplot(line @b @at,lcolor(blue)) ciopts(lpattern(dash) lcolor(gray) recast(rline) msize(medium)) msymbol(O) mcolor(blue) scheme(s1mono)

*** data preparation
gen ee_lag=a_lag+b_lag+c_lag+d_lag+e_lag
gen mm_lag=m_lag+nn_lag
winsor2 ee_lag, cut(0 97.5) replace
** Fig 5b
reghdfe OAPratio ee_lag f_lag g_lag h_lag i_lag tier k_lag l_lag mm_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id)

coefplot, baselevels omitted keep(mm_lag l_lag k_lag i_lag tier h_lag g_lag f_lag ee_lag) vertical coeflabels(ee_lag = "<-5°C" f_lag = "-5-0°C" g_lag = "0-5°C" h_lag = "5-10°C" i_lag = "10-15°C"  tier = "15-20°C" k_lag = "20-25°C" l_lag = "25-30°C" mm_lag = ">30°C") yline(0,lcolor(red*0.9) lwidth(medthick)) yline(-0.003,lcolor(blue*0.2)) yline(-0.002,lcolor(blue*0.2)) yline(-0.001,lcolor(blue*0.2)) yline(0.001,lcolor(blue*0.2)) yline(0.002,lcolor(blue*0.2)) yline(0.003,lcolor(blue*0.2)) yline(0.004,lcolor(blue*0.2)) ylabel(-0.003(0.001)0.004) xline(10, lwidth(vthin) lpattern(dash) lcolor(red)) ylabel(,labsize(*0.9)) xlabel(,labsize(*0.9))  ytitle("Change in OAP ratio", size(medium)) xtitle("Daily average temperature bins in t-1", size(medium)) addplot(line @b @at,lcolor(blue)) ciopts(lpattern(dash) lcolor(gray) recast(rline) msize(medium)) msymbol(O) mcolor(blue) scheme(s1mono)

*** data preparation 
gen LNOAR=log(OAR)
gen LNdebt1=log(debt)
gen OARratio=LNOAR-LNdebt1
winsor2 OARratio, cut(2.5 100) trim
*** Table A2
reghdfe OARratio_tr daysextrm daysextrm_lag daysextrm_lag2 daysextrm_lag3 daysextrm_lag4 daysextrm_lag5 daysextrm_lag6 daysextrm_lag7 precip precip2 wspeed sunshine precip_lag precip2_lag wspeed_lag sunshine_lag precip_lag2 precip2_lag2 wspeed_lag2 sunshine_lag2 precip_lag3 precip2_lag3 wspeed_lag3 sunshine_lag3 precip_lag4 precip2_lag4 wspeed_lag4 sunshine_lag4 precip_lag5 precip2_lag5 wspeed_lag5 sunshine_lag5 precip_lag6 precip2_lag6 wspeed_lag6 sunshine_lag6 precip_lag7 precip2_lag7 wspeed_lag7 sunshine_lag7 LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id)

** Fig 5c
reghdfe OARratio_tr one_lag4 two_lag4 three_lag4 four_lag4 five_lag4 six_lag4 tier eight_lag4 nine_lag4 precip_lag4 precip2_lag4 wspeed_lag4 sunshine_lag4 LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id)

coefplot, baselevels omitted keep(nine_lag4 eight_lag4 six_lag4 tier five_lag4 four_lag4 three_lag4 two_lag4 one_lag4) vertical coeflabels(one_lag4 = "<0°C" two_lag4 = "0-5°C" three_lag4 = "5-10°C" four_lag4 = "10-15°C" five_lag4 = "15-20°C" six_lag4 = "20-25°C" tier = "25-30°C" eight_lag4 = "30-35°C" nine_lag4 = ">35°C") yline(0,lcolor(red*0.9) lwidth(medthick)) yline(-0.002,lcolor(blue*0.2)) yline(-0.001,lcolor(blue*0.2)) yline(0.001,lcolor(blue*0.2)) yline(0.002,lcolor(blue*0.2)) yline(0.003,lcolor(blue*0.2)) yline(0.004,lcolor(blue*0.2)) yline(0.005,lcolor(blue*0.2)) yline(0.006,lcolor(blue*0.2)) ylabel(-0.002(0.001)0.006) xline(10, lwidth(vthin) lpattern(dash) lcolor(red)) ylabel(,labsize(*0.9)) xlabel(,labsize(*0.9))  ytitle("Change in OAR ratio", size(medium)) xtitle("Daily max temperature bins in t-4", size(medium)) addplot(line @b @at,lcolor(blue)) ciopts(lpattern(dash) lcolor(gray) recast(rline) msize(medium)) msymbol(O) mcolor(blue) scheme(s1mono)

** Fig 5d
xtset id quarter
gen ee_lag4=L75.ee_lag
gen mm_lag4=L75.mm_lag
winsor2 ee_lag4, cut(0 97.5) replace
reghdfe OARratio_tr ee_lag4 f_lag4 g_lag4 h_lag4 i_lag4 j_lag4 tier l_lag4 mm_lag4 precip_lag4 precip2_lag4 wspeed_lag4 sunshine_lag4 LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id)

coefplot, baselevels omitted keep(mm_lag4 l_lag4 j_lag4 i_lag4 tier h_lag4 g_lag4 f_lag4 ee_lag4) vertical coeflabels(ee_lag4 = "<-5°C" f_lag4 = "-5-0°C" g_lag4 = "0-5°C" h_lag4 = "5-10°C" i_lag4 = "10-15°C"  j_lag4 = "15-20°C" tier = "20-25°C" l_lag4 = "25-30°C" mm_lag4 = ">30°C") yline(0,lcolor(red*0.9) lwidth(medthick)) yline(-0.002,lcolor(blue*0.2)) yline(-0.001,lcolor(blue*0.2)) yline(0.001,lcolor(blue*0.2)) yline(0.002,lcolor(blue*0.2)) yline(0.003,lcolor(blue*0.2)) yline(0.005,lcolor(blue*0.2)) yline(0.006,lcolor(blue*0.2)) yline(0.004,lcolor(blue*0.2)) ylabel(-0.002(0.001)0.006) xline(10, lwidth(vthin) lpattern(dash) lcolor(red)) ylabel(,labsize(*0.9)) xlabel(,labsize(*0.9))  ytitle("Change in OAR ratio", size(medium)) xtitle("Daily average temperature bins in t-4", size(medium)) addplot(line @b @at,lcolor(blue)) ciopts(lpattern(dash) lcolor(gray) recast(rline) msize(medium)) msymbol(O) mcolor(blue) scheme(s1mono)


* 5.4.1 Mechanism analysis
** Table 6
*** data preparation
gen LNEGDP=log(EGDP)
gen LNELEC=log(ELEC)
gen LNEE=LNEGDP-LNELEC
gen nineLNEE=nine_lag*LNEE
gen one1LNEE=one1_lag*LNEE
gen daysextrmLNEE=daysextrm_lag*LNEE
*** column 1
reghdfe OAPratio nineLNEE one1LNEE nine_lag one1_lag LNEE precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id)
*** column 2
reghdfe OAPratio daysextrmLNEE daysextrm_lag LNEE precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id)
*** data preparation
gen popflow1=permresi/regiresi
gen ninepopflow=nine_lag*popflow
gen one1popflow=one1_lag*popflow
gen daysextrmpopflow=daysextrm_lag*popflow
*** column 3
reghdfe OAPratio ninepopflow one1popflow nine_lag one1_lag popflow precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id)
*** column 4
reghdfe OAPratio daysextrmpopflow daysextrm_lag popflow precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id)

* 5.4.2 Heterogeneity across different market integration 
** Table 7
*** data preparation
gen Mseg2=Mseg^2
gen nineMseg=nine_lag*Mseg
gen nineMseg2=nine_lag*Mseg2
gen one1Mseg=one1_lag*Mseg
gen one1Mseg2=one1_lag*Mseg2
gen daysextrmMseg=daysextrm_lag*Mseg
gen daysextrmMseg2=daysextrm_lag*Mseg2
*** column 1
reghdfe OAPratio nineMseg nineMseg2 one1Mseg one1Mseg2 Mseg Mseg2 nine_lag one1_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id)
*** column 2
reghdfe OAPratio daysextrmMseg daysextrmMseg2 Mseg Mseg2 daysextrm_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id)

* 5.4.3 Heterogeneity across prefecture and county-level LGFVs
** Table 8
*** data preparation
gen ninetier=nine_lag*tier
gen one1tier=one1_lag*tier
gen daysextrmtier=daysextrm_lag*tier
***column 1
reghdfe OAPratio ninetier one1tier tier nine_lag one1_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id)
***column 2
reghdfe OAPratio daysextrmtier tier daysextrm_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id)

* 5.4.4 Heterogeneity across different spending efficiency
** Table 9
***column 1
reghdfe OAPratio nine_lag one1_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id),if compact>0.88
***column 2
reghdfe OAPratio nine_lag one1_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id),if compact<0.88
***column 3
reghdfe OAPratio daysextrm_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id),if compact>0.88
***column 4
reghdfe OAPratio daysextrm_lag precip_lag precip2_lag wspeed_lag sunshine_lag LNcash LNincome LNdebt urbaniz compact deficit, absorb(id quarter) vce(cluster id),if compact<0.88

* export the results
outreg2 using tableX.doc, append bdec(4) sdec(4) rdec(4)